package com.quiz.bis.controller;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.quiz.bis.domain.bo.BisQuestionsSaveBo;
import com.quiz.bis.domain.bo.BisQuestionsBo;
import com.quiz.bis.domain.excel.BisQuestionsExcel;
import com.quiz.bis.domain.vo.BisQuestionsVo;
import com.quiz.bis.service.IBisQuestionsService;
import com.quiz.common.mybatis.core.page.PageQuery;
import com.quiz.common.mybatis.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.quiz.common.annotation.Log;
import com.quiz.common.core.controller.BaseController;
import com.quiz.common.core.domain.AjaxResult;
import com.quiz.common.enums.BusinessType;
import com.quiz.common.utils.poi.ExcelUtil;

/**
 * 题目Controller
 *
 * @author ahuan
 */
@RestController
@RequestMapping("/question/manage")
@Tag(name = "题目管理")
@RequiredArgsConstructor
public class BisQuestionsController extends BaseController {

    private final IBisQuestionsService bisQuestionsService;

    /**
     * 查询题目列表
     *
     * @param bisQuestionsBo 题目实体类
     * @return {@link TableDataInfo}<{@link BisQuestionsVo}>
     */
    @PreAuthorize("@ss.hasPermi('question:questions:list')")
    @GetMapping("/list")
    public TableDataInfo<BisQuestionsVo> page(BisQuestionsBo bisQuestionsBo , PageQuery page) {
        return bisQuestionsService.selectBisQuestionsPage(bisQuestionsBo, BisQuestionsVo.class, page);
    }

    /**
     * 导出题目列表
     *
     * @param bisQuestionsBo 题目实体类BO
     */
    @PreAuthorize("@ss.hasPermi('question:questions:export')")
    @Log(title = "题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisQuestionsBo bisQuestionsBo) {
        List<BisQuestionsExcel> list = bisQuestionsService.selectBisQuestionsList(bisQuestionsBo, BisQuestionsExcel.class);
        ExcelUtil<BisQuestionsExcel> util = new ExcelUtil<>(BisQuestionsExcel.class);
        util.exportExcel(response, list, "题目数据");
    }

    /**
     * 获取题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:questions:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") Long questionId) {
        return success(bisQuestionsService.selectBisQuestionsByQuestionId(questionId));
    }

    /**
     * 新增题目
     */
    @PreAuthorize("@ss.hasPermi('question:questions:add')")
    @Log(title = "题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BisQuestionsSaveBo bo) {
        return toAjax(bisQuestionsService.insertBisQuestions(bo));
    }

    /**
     * 修改题目
     */
    @PreAuthorize("@ss.hasPermi('question:questions:edit')")
    @Log(title = "题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BisQuestionsSaveBo bisQuestions) {
        return toAjax(bisQuestionsService.updateBisQuestions(bisQuestions));
    }

    /**
     * 删除题目
     */
    @PreAuthorize("@ss.hasPermi('question:questions:remove')")
    @Log(title = "题目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable Long[] questionIds) {
        return toAjax(bisQuestionsService.deleteBisQuestionsByQuestionIds(questionIds));
    }
}

